<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>

    <script type="text/javascript">
        let ws;
        window.onload=function(){
            if ("WebSocket" in window){
                console.log("您的浏览器支持 WebSocket!");
                ws = new WebSocket("ws://localhost:9001/loginTurck/connect?userid=1");
                ws.onopen = function(){
                    console.log("连接打开...");
                };
                ws.onmessage = function (evt){
                    var received_msg = evt.data;
                    console.log("接收到数据: " + received_msg);
                };
                ws.onclose = function(){
                    console.log("连接关闭...");
                };
            }else{
                console.log("您的浏览器不支持 WebSocket!");
            }
        }
        function send(){
            var test = document.getElementById("test");
            var text2 = test.value; //方法2
            ws.send(text2);
        }
    </script>

</head>
<body>

<div id="sse">
    <textarea id="test"></textarea>
    <input type="button" onclick="send()" value="发送">
</div>

</body>
</html>